<?php

namespace Modules\Admin\Services\auth;

use Illuminate\Support\Facades\Auth;
use Modules\Admin\Models\AuthAdmin;
use Modules\Admin\Services\BaseApiService;

class LoginService extends BaseApiService
{

    public function login(array $data)
    {

        if(true == Auth::guard('auth_admin')->attempt($data)){
            $userInfo = AuthAdmin::where(['username'=>$data['username']])->select('id','username')->first();
            dd($userInfo);
            if($userInfo){
                $userInfo = $userInfo->toArray();
                $userInfo['password'] = $data['password'];
                return $this->apiSuccess('登录成功！', (new TokenService())->setToken($userInfo));
            }

        }
        return $this->apiError("账号或密码错误！");
    }


}
